package com.yc.thread;

public class JoinDemo {

    public static void main(String[] args) {

        Thread t1 = new Thread("mythread1  "){
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    Thread t = Thread.currentThread();
                    System.out.println(t.getName() + i);
                }
            }
        };

        // lambda表达式 =》 匿名类的简化语法
        Thread t2 = new Thread(()-> {
            for (int i = 0; i < 100; i++) {
                Thread t = Thread.currentThread();
                System.out.println(t.getName() + i);

                if(i==50){
                    System.out.println("================================");
                    try {
                        t1.join();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }, "myhread2  ");

        t2.start();
        t1.start();

    }

}
